﻿//-----------------------------------------------------------------
//
// @(#)$Id: DisputeMessageDetail.aspx.cs,v 1.0 2013/12/13 16:59:17 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/13 16:59:17 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using ebay.Dal.CenterDB_EbayTableAdapters;
using eBay.Service.Core.Soap;

public partial class UI_Bas_DisputeMessageDetail : System.Web.UI.Page
{
    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        //DisputeStatusCodeType 投诉类型
        string[] status = Enum.GetNames(typeof(DisputeStatusCodeType));
        foreach (string stat in status)
        {
            if (stat != "CustomCode")
            {
                ddlDisputeStatus.Items.Add(stat);
            }
        }
        ddlDisputeStatus.SelectedIndex = 0;
    }

    string act="";
    protected void Page_Load(object sender, EventArgs e)
    {
        act = Request.QueryString["act"];
        if (!IsPostBack)
        {          
            switch (act)
            {
                case "I":
                    {
                        txtDisputeID.Value = Request.QueryString["id"];
                        txtEbayUserId.Value = Request.QueryString["id2"];
                        txtMessageSource.Value = "邮件";
                        txtMessageCreationTime.Value = DateTime.Now.ToString();
                    }
                    break;
                case "U":
                    break;
            }
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(act))
        {
            switch (act)
            {
                case "I":
                    {
                        //txtDisputeID.Value = Request.QueryString["id"];
                        //txtEbayUserId.Value = Request.QueryString["id2"];
                        //T_EbayDisputeMessageTableAdapter mesAdapter = new T_EbayDisputeMessageTableAdapter();
                        //int val = mesAdapter.Insert(
                        //    txtEbayUserId.Value, txtDisputeID.Value,
                        //    txtMessageID.Value, txtMessageSource.Value,
                        //    DateTime.Now, txtMessageText.Value
                        //    );
                       // if (val > 0)
                       // {
                            T_EbayDisputeTableAdapter disAdapter = new T_EbayDisputeTableAdapter();
                            DataTable dt = disAdapter.GetDataById(txtEbayUserId.Value, txtDisputeID.Value);
                            DataRow r = dt.Rows[0];
                            if (dt.Rows.Count > 0)
                            {
                                foreach (Control ctr in form1.Controls)
                                {
                                    if (ctr is HtmlInputText)
                                    {
                                        HtmlInputText txtbox = (HtmlInputText)ctr;
                                        string name = txtbox.ID.Substring(3, txtbox.ID.Length - 3);
                                        foreach (DataColumn col in dt.Columns)
                                        {
                                            if (col.ColumnName.ToString() == name)
                                            {
                                                r[name] = txtbox.Value;
                                            }
                                        }
                                    }
                                    else if (ctr is DropDownList)
                                    {
                                        DropDownList ddlist = (DropDownList)ctr;
                                        string name = ddlist.ID.Substring(3, ddlist.ID.Length - 3);
                                        foreach (DataColumn col in dt.Columns)
                                        {
                                            if (col.ColumnName.ToString() == name)
                                            {
                                                r[name] = ddlist.SelectedValue;
                                            }
                                        }
                                    }
                                }                               
                            }
                            int val2 = disAdapter.Update(r);
                            if (val2 > 0)
                            {
                                Response.Write("<script>alert('添加成功!');window.location.href='DisputeDetail.aspx?act=view&id=" + txtDisputeID.Value + "&id2=" + txtEbayUserId.Value + "'</script>");
                            }
                       // }
                    }
                    break;
                case "U":
                    break;
            }
        }
    }
}
